using Godot;
using System;

public partial class DashOnFloor : Node,StateNode
{
	public Enemy enemy;

	public Player player;

	public Timer timer;

	[Export]
	public int dashSpeed = 700;

	public override void _Ready()
	{
		enemy = GetNode<Enemy>("/root/Main/Enemy");
		
		player = GetNode<Player>("/root/Main/Player");

		timer = GetNode<Timer>("Timer");
		timer.OneShot = true;
		timer.Timeout+=OnTimeout;
	}

    private void OnTimeout()
    {
        enemy.SwitchTo("Idle");
    }

    public void OnDash()
	{
		enemy.Velocity = new((enemy.FacingLeft?-1:1)*dashSpeed,0);

		enemy.GetNode<AudioStreamPlayer2D>("DashMusic").Play();
	}

    public void OnEnter()
    {
        enemy.GetNode<AnimatedSprite2D>("AnimaEnemy").Animation = "dash_on_floor";
		OnDash();
		timer.Start();
    }

    public void OnUpdate(float delta)
    {
		if(enemy.Health<=0)
			enemy.SwitchTo("Dead");
    }

    public void OnExit()
    {
		enemy.Velocity = new(0,0);
    }

}
